package com.goods.business.service.imp;

import com.goods.business.mapper.SupplierMapper;
import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.utils.ListPageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> findSupplierList(Integer pageNum, Integer pageSize, String name, String address, String contact){

        List<Supplier> select = supplierMapper.selectSupplierList(name,address,contact);
        List<Supplier> page = ListPageUtils.page(select, pageSize, pageNum);
        return page;


    }

    @Override
    public Boolean add(Supplier supplier) {
        supplier.setCreateTime(Calendar.getInstance().getTime());
        supplier.setModifiedTime(Calendar.getInstance().getTime());
        int insert = supplierMapper.insert(supplier);
        return insert==1;
    }

    @Override
    public Supplier edit(int id) {
        Supplier supplier = supplierMapper.selectByPrimaryKey(id);
        return supplier;
    }

    @Override
    public void update(Supplier supplier) {
        supplier.setModifiedTime(Calendar.getInstance().getTime());
        supplierMapper.updateByPrimaryKeySelective(supplier);
    }

    @Override
    public void delete(int id) {
        supplierMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Supplier> findAll() {
        List<Supplier> supplierList = supplierMapper.selectAll();
        return supplierList;
    }
}
